
<h1>Go compilers will automatically insert some semicolons in code</h1>

<p>Let's view a small program:</p>

<pre><code class="language-Go">package main

func foo() bool {
	return false
}

func main() {
	switch foo()
	{
	case false: println(&quot;False&quot;)
	case true: println(&quot;True&quot;)
	}
}
</code></pre>

<p>What is the output of the above program? Let's think for a while.</p>

<p>~</p>

<p>~</p>

<p>~</p>

<p><code>False</code>? No, it prints <code>True</code>.
Surprised? Doesn't the function <code>foo</code> always return <code>false</code>?</p>

<p>Yes, the function <code>foo</code> always returns <code>false</code>, but this is unrelated here.</p>

<p>Compilers will automatically insert some semicolons for the above code as:</p>

<pre><code class="language-Go">package main

func foo() bool {
	return false;
};

func main() {
	switch foo();
	{
	case false: println(&quot;False&quot;);
	case true: println(&quot;True&quot;);
	};
};
</code></pre>

<p>Now, it clearly shows that the <code>switch</code> expression (<code>true</code>) is omitted.
The <code>switch</code> block is actually equivalent to:</p>

<pre><code class="language-Go">	switch foo(); true
	{
	case false: println(&quot;False&quot;);
	case true: println(&quot;True&quot;);
	};
</code></pre>

<p>That is why the program prints <code>True</code>.</p>

<p>About detailed semicolon insertion rules, please read <a href="https://go101.org/article/line-break-rules.html">this article</a>.</p>
